<template>
    <div id="AddNewConfig">
        <el-dialog
        title="新增配置"
        :visible="dialogVisible"
        width="30%"
        :before-close="handleClose"
        >
            <table class="table table-bordered">
                <tbody>
                    <tr>
                        <td>类型</td>
                        <td>
                            <el-input v-model="configData.ktype"></el-input>
                        </td>
                    </tr>
                    <tr>
                        <td>键</td>
                        <td>
                             <el-input v-model="configData.kkey"></el-input>
                        </td>
                    </tr>
                    <tr>
                        <td>值</td>
                        <td>
                            <el-input v-model="configData.kvalue"></el-input>                    
                        </td>
                    </tr>
                </tbody>
                <tfoot>
                    <tr>
                        <td colspan="2" style="text-align:right">
                            <el-button type="danger" @click="handleClose">取消</el-button>
                            <el-button type="primary" @click="commit">提交</el-button>
                        </td>
                    </tr>
                </tfoot>
            </table>
        </el-dialog>
    </div>
</template>

<script>
export default {
    data(){
        return {
            dialogVisible: true,
            configData: {
                ktype: ''
            },
            offset: Number(10),
        }
    },
    methods: {
        handleClose(){
            this.$router.go(-1);
        },
        commit(){
            var insertURL = window.baseURL + "/backstage/config/insert";
            this.configData.ktype = this.configData.ktype.trim();
            var data = this.configData;
            data.token = this.$token;
            if(data.ktype.length!=0&&data.kkey.length!=0&&data.kvalue.length!=0){
                this.$http.post(insertURL,this.$qs.stringify(data))
                .then((response)=>{
                })
                .catch((error)=>{

                })
            }
           this.handleClose();
        }
    },
    created(){
        this.dialogVisible = true;
        if(!this.$route.params.keyType){
            this.$router.go(-1)
        }else{
            this.configData.ktype = this.$route.params.keyType;
            this.configData.kkey = this.$route.params.kkey;
        }
    }
}
</script>
<style lang="scss" scoped>
    td:nth-child(2n-1){
        text-align: center;
        vertical-align: middle;
    }
</style>
